package tree.easy;

import tree.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * 897. 递增顺序搜索树
 */
public class increasingBST {

    public TreeNode increasingBST(TreeNode root) {
        TreeNode treeNode = new TreeNode();
        List<Integer> list = new ArrayList<>();
        inorder(root, list);
        return tree(list, 0);
    }

    public void inorder(TreeNode node, List<Integer> res) {
        if (node == null) {
            return;
        }
        inorder(node.left, res);
        res.add(node.val);
        inorder(node.right, res);

    }

    public TreeNode tree(List<Integer> list, int index) {
        if (index == list.size()) {
            return null;
        }
        TreeNode treeNode = new TreeNode(list.get(index));
        treeNode.right = tree(list, index + 1);
        return treeNode;
    }
}
